{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Block Aligner Benchmark Analysis and Visualizations"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This notebook contains code for collecting, cleaning, and analyzing data produced by block aligner's experiments.\n",
    "\n",
    "To run this, you will need to install all the libraries imported below, along with [altair-saver](https://github.com/altair-viz/altair_saver) and [altair-data-server](https://github.com/altair-viz/altair_data_server), which has some extra dependencies for PDF saving.\n",
    "\n",
    "Run each cell one by one to reproduce the experiments. This may take a while. For accurate benchmarking, it is recommended to run the entire notebook in the command line with `nbconvert`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:14:39.004205Z",
     "iopub.status.busy": "2023-02-27T11:14:39.003434Z",
     "iopub.status.idle": "2023-02-27T11:14:40.467921Z",
     "shell.execute_reply": "2023-02-27T11:14:40.468330Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DataTransformerRegistry.enable('data_server')"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import altair as alt\n",
    "from altair_saver import save\n",
    "from altair import datum\n",
    "import pandas as pd\n",
    "from io import StringIO\n",
    "\n",
    "alt.data_transformers.enable(\"data_server\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:14:40.471391Z",
     "iopub.status.busy": "2023-02-27T11:14:40.470954Z",
     "iopub.status.idle": "2023-02-27T11:14:40.472356Z",
     "shell.execute_reply": "2023-02-27T11:14:40.472852Z"
    }
   },
   "outputs": [],
   "source": [
    "def csv_to_pandas(csv, d = \"\\\\s*,\\\\s*\", t = None):\n",
    "    s = StringIO(\"\\n\".join(csv))\n",
    "    data = pd.read_csv(s, sep = d, thousands = t, comment = \"#\", engine = \"python\")\n",
    "    return data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Prefix Scan Benchmark"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:14:40.475746Z",
     "iopub.status.busy": "2023-02-27T11:14:40.475308Z",
     "iopub.status.idle": "2023-02-27T11:15:01.464856Z",
     "shell.execute_reply": "2023-02-27T11:15:01.465354Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['algorithm\\ttime', 'bench_naive_prefix_scan\\t26', 'bench_opt_prefix_scan\\t18']"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "output = !cd .. && cargo bench --features simd_avx2 --quiet -- prefix_scan | grep 'bench:' | awk '{print $2\"\\t\"$5}'\n",
    "output.insert(0, \"algorithm\\ttime\")\n",
    "output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:15:01.468890Z",
     "iopub.status.busy": "2023-02-27T11:15:01.468374Z",
     "iopub.status.idle": "2023-02-27T11:15:01.480729Z",
     "shell.execute_reply": "2023-02-27T11:15:01.481235Z"
    },
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>algorithm</th>\n",
       "      <th>time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>bench_naive_prefix_scan</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>bench_opt_prefix_scan</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 algorithm  time\n",
       "0  bench_naive_prefix_scan    26\n",
       "1    bench_opt_prefix_scan    18"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = csv_to_pandas(output, d = \"\\t\", t = \",\")\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:15:01.486965Z",
     "iopub.status.busy": "2023-02-27T11:15:01.486359Z",
     "iopub.status.idle": "2023-02-27T11:15:01.488535Z",
     "shell.execute_reply": "2023-02-27T11:15:01.489034Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>algorithm</th>\n",
       "      <th>time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>naive</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ours</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  algorithm  time\n",
       "0     naive    26\n",
       "1      ours    18"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[\"algorithm\"] = data[\"algorithm\"].map({\n",
    "    \"bench_naive_prefix_scan\": \"naive\",\n",
    "    \"bench_opt_prefix_scan\": \"ours\"\n",
    "})\n",
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Prefix Scan Benchmark (AVX2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:15:01.497427Z",
     "iopub.status.busy": "2023-02-27T11:15:01.496945Z",
     "iopub.status.idle": "2023-02-27T11:15:03.645465Z",
     "shell.execute_reply": "2023-02-27T11:15:03.645874Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<div id=\"altair-viz-26db691fe82347dfae3c35d263e21809\"></div>\n",
       "<script type=\"text/javascript\">\n",
       "  (function(spec, embedOpt){\n",
       "    let outputDiv = document.currentScript.previousElementSibling;\n",
       "    if (outputDiv.id !== \"altair-viz-26db691fe82347dfae3c35d263e21809\") {\n",
       "      outputDiv = document.getElementById(\"altair-viz-26db691fe82347dfae3c35d263e21809\");\n",
       "    }\n",
       "    const paths = {\n",
       "      \"vega\": \"https://cdn.jsdelivr.net/npm//vega@5?noext\",\n",
       "      \"vega-lib\": \"https://cdn.jsdelivr.net/npm//vega-lib?noext\",\n",
       "      \"vega-lite\": \"https://cdn.jsdelivr.net/npm//vega-lite@4.8.1?noext\",\n",
       "      \"vega-embed\": \"https://cdn.jsdelivr.net/npm//vega-embed@6?noext\",\n",
       "    };\n",
       "\n",
       "    function loadScript(lib) {\n",
       "      return new Promise(function(resolve, reject) {\n",
       "        var s = document.createElement('script');\n",
       "        s.src = paths[lib];\n",
       "        s.async = true;\n",
       "        s.onload = () => resolve(paths[lib]);\n",
       "        s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
       "        document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "      });\n",
       "    }\n",
       "\n",
       "    function showError(err) {\n",
       "      outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
       "      throw err;\n",
       "    }\n",
       "\n",
       "    function displayChart(vegaEmbed) {\n",
       "      vegaEmbed(outputDiv, spec, embedOpt)\n",
       "        .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
       "    }\n",
       "\n",
       "    if(typeof define === \"function\" && define.amd) {\n",
       "      requirejs.config({paths});\n",
       "      require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
       "    } else if (typeof vegaEmbed === \"function\") {\n",
       "      displayChart(vegaEmbed);\n",
       "    } else {\n",
       "      loadScript(\"vega\")\n",
       "        .then(() => loadScript(\"vega-lite\"))\n",
       "        .then(() => loadScript(\"vega-embed\"))\n",
       "        .catch(showError)\n",
       "        .then(() => displayChart(vegaEmbed));\n",
       "    }\n",
       "  })({\"config\": {\"view\": {\"continuousWidth\": 400, \"continuousHeight\": 300}}, \"data\": {\"url\": \"http://localhost:23517/2336296bfa4075f43c55ef1138a92f78.json\"}, \"mark\": \"bar\", \"encoding\": {\"color\": {\"type\": \"nominal\", \"field\": \"algorithm\", \"legend\": null}, \"x\": {\"type\": \"quantitative\", \"axis\": {\"title\": \"time (ns)\"}, \"field\": \"time\"}, \"y\": {\"type\": \"nominal\", \"field\": \"algorithm\"}}, \"width\": 150, \"$schema\": \"https://vega.github.io/schema/vega-lite/v4.8.1.json\"}, {\"mode\": \"vega-lite\"});\n",
       "</script>"
      ],
      "text/plain": [
       "alt.Chart(...)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = alt.Chart(data).mark_bar().encode(\n",
    "    x = alt.X(\"time\", axis = alt.Axis(title = \"time (ns)\")),\n",
    "    y = \"algorithm\",\n",
    "    color = alt.Color(\"algorithm\", legend = None)\n",
    ").properties(\n",
    "    width = 150\n",
    ")\n",
    "save(c, \"prefix_scan_bench.pdf\")\n",
    "c"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Random Data Benchmark"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:15:03.649500Z",
     "iopub.status.busy": "2023-02-27T11:15:03.649097Z",
     "iopub.status.idle": "2023-02-27T11:15:53.919996Z",
     "shell.execute_reply": "2023-02-27T11:15:53.920443Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['bench_parasailors_aa_1000_10000\\t52,435,895',\n",
       " 'bench_parasailors_aa_100_1000\\t608,499',\n",
       " 'bench_parasailors_aa_10_100\\t20,155',\n",
       " 'bench_rustbio_aa_100_1000\\t15,363,409',\n",
       " 'bench_rustbio_aa_10_100\\t170,271',\n",
       " 'bench_scan_aa_1000_10000\\t231,190',\n",
       " 'bench_scan_aa_1000_10000_insert\\t4,913,574',\n",
       " 'bench_scan_aa_1000_10000_small\\t220,464',\n",
       " 'bench_scan_aa_1000_10000_trace\\t1,861,712',\n",
       " 'bench_scan_aa_100_1000\\t26,275',\n",
       " 'bench_scan_aa_100_1000_insert\\t50,462',\n",
       " 'bench_scan_aa_100_1000_small\\t23,579',\n",
       " 'bench_scan_aa_100_1000_trace\\t514,997',\n",
       " 'bench_scan_aa_10_100\\t3,939',\n",
       " 'bench_scan_aa_10_100_insert\\t4,071',\n",
       " 'bench_scan_aa_10_100_small\\t3,486',\n",
       " 'bench_scan_aa_10_100_trace\\t368,967',\n",
       " 'bench_scan_nuc_1000_10000\\t223,067',\n",
       " 'bench_scan_nuc_100_1000\\t24,061',\n",
       " 'bench_triple_accel_1000_10000\\t8,404,724',\n",
       " 'bench_triple_accel_100_1000\\t24,589']"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "output = !cd .. && cargo bench --features simd_avx2 --quiet -- bench_ | grep 'bench:' | grep -v 'prefix_scan' | awk '{print $2\"\\t\"$5}'\n",
    "output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:15:53.925902Z",
     "iopub.status.busy": "2023-02-27T11:15:53.925149Z",
     "iopub.status.idle": "2023-02-27T11:15:53.927406Z",
     "shell.execute_reply": "2023-02-27T11:15:53.927851Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['algorithm\\talphabet\\tk\\tlength\\tproperty\\ttime',\n",
       " 'parasailors\\tprotein\\t1000\\t10000\\tdefault\\t52,435,895',\n",
       " 'parasailors\\tprotein\\t100\\t1000\\tdefault\\t608,499',\n",
       " 'parasailors\\tprotein\\t10\\t100\\tdefault\\t20,155',\n",
       " 'rust bio\\tprotein\\t100\\t1000\\tdefault\\t15,363,409',\n",
       " 'rust bio\\tprotein\\t10\\t100\\tdefault\\t170,271',\n",
       " 'ours\\tprotein\\t1000\\t10000\\tdefault\\t231,190',\n",
       " 'ours\\tprotein\\t1000\\t10000\\tinsert\\t4,913,574',\n",
       " 'ours\\tprotein\\t1000\\t10000\\tsmall\\t220,464',\n",
       " 'ours\\tprotein\\t1000\\t10000\\ttrace\\t1,861,712',\n",
       " 'ours\\tprotein\\t100\\t1000\\tdefault\\t26,275',\n",
       " 'ours\\tprotein\\t100\\t1000\\tinsert\\t50,462',\n",
       " 'ours\\tprotein\\t100\\t1000\\tsmall\\t23,579',\n",
       " 'ours\\tprotein\\t100\\t1000\\ttrace\\t514,997',\n",
       " 'ours\\tprotein\\t10\\t100\\tdefault\\t3,939',\n",
       " 'ours\\tprotein\\t10\\t100\\tinsert\\t4,071',\n",
       " 'ours\\tprotein\\t10\\t100\\tsmall\\t3,486',\n",
       " 'ours\\tprotein\\t10\\t100\\ttrace\\t368,967',\n",
       " 'ours\\tnucleotide\\t1000\\t10000\\tdefault\\t223,067',\n",
       " 'ours\\tnucleotide\\t100\\t1000\\tdefault\\t24,061',\n",
       " 'triple accel\\tnucleotide\\t1000\\t10000\\tdefault\\t8,404,724',\n",
       " 'triple accel\\tnucleotide\\t100\\t1000\\tdefault\\t24,589']"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cleaned = [\"algorithm\\talphabet\\tk\\tlength\\tproperty\\ttime\"]\n",
    "names = [\"parasailors_aa\", \"rustbio_aa\", \"scan_aa\", \"scan_nuc\", \"triple_accel\"]\n",
    "new_names = [\"parasailors\\tprotein\", \"rust bio\\tprotein\", \"ours\\tprotein\", \"ours\\tnucleotide\", \"triple accel\\tnucleotide\"]\n",
    "\n",
    "for o in output:\n",
    "    o = o[len(\"bench_\"):]\n",
    "    for n, nn in zip(names, new_names):\n",
    "        if o.startswith(n):\n",
    "            suffix = o[len(n):].replace(\"_\", \"\\t\")\n",
    "            o = nn + suffix\n",
    "            break\n",
    "    if len(o.split(\"\\t\")) < len(cleaned[0].split(\"\\t\")):\n",
    "        insert_idx = o.rindex(\"\\t\")\n",
    "        o = o[:insert_idx] + \"\\tdefault\" + o[insert_idx:]\n",
    "    cleaned.append(o)\n",
    "\n",
    "cleaned"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:15:53.930417Z",
     "iopub.status.busy": "2023-02-27T11:15:53.930017Z",
     "iopub.status.idle": "2023-02-27T11:15:53.940656Z",
     "shell.execute_reply": "2023-02-27T11:15:53.940932Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>algorithm</th>\n",
       "      <th>alphabet</th>\n",
       "      <th>k</th>\n",
       "      <th>length</th>\n",
       "      <th>property</th>\n",
       "      <th>time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>parasailors</td>\n",
       "      <td>protein</td>\n",
       "      <td>1000</td>\n",
       "      <td>10000</td>\n",
       "      <td>default</td>\n",
       "      <td>52435895</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>parasailors</td>\n",
       "      <td>protein</td>\n",
       "      <td>100</td>\n",
       "      <td>1000</td>\n",
       "      <td>default</td>\n",
       "      <td>608499</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>parasailors</td>\n",
       "      <td>protein</td>\n",
       "      <td>10</td>\n",
       "      <td>100</td>\n",
       "      <td>default</td>\n",
       "      <td>20155</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>rust bio</td>\n",
       "      <td>protein</td>\n",
       "      <td>100</td>\n",
       "      <td>1000</td>\n",
       "      <td>default</td>\n",
       "      <td>15363409</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>rust bio</td>\n",
       "      <td>protein</td>\n",
       "      <td>10</td>\n",
       "      <td>100</td>\n",
       "      <td>default</td>\n",
       "      <td>170271</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>1000</td>\n",
       "      <td>10000</td>\n",
       "      <td>default</td>\n",
       "      <td>231190</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>1000</td>\n",
       "      <td>10000</td>\n",
       "      <td>insert</td>\n",
       "      <td>4913574</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>1000</td>\n",
       "      <td>10000</td>\n",
       "      <td>small</td>\n",
       "      <td>220464</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>1000</td>\n",
       "      <td>10000</td>\n",
       "      <td>trace</td>\n",
       "      <td>1861712</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>100</td>\n",
       "      <td>1000</td>\n",
       "      <td>default</td>\n",
       "      <td>26275</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>100</td>\n",
       "      <td>1000</td>\n",
       "      <td>insert</td>\n",
       "      <td>50462</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>100</td>\n",
       "      <td>1000</td>\n",
       "      <td>small</td>\n",
       "      <td>23579</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>100</td>\n",
       "      <td>1000</td>\n",
       "      <td>trace</td>\n",
       "      <td>514997</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>10</td>\n",
       "      <td>100</td>\n",
       "      <td>default</td>\n",
       "      <td>3939</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>10</td>\n",
       "      <td>100</td>\n",
       "      <td>insert</td>\n",
       "      <td>4071</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>10</td>\n",
       "      <td>100</td>\n",
       "      <td>small</td>\n",
       "      <td>3486</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>10</td>\n",
       "      <td>100</td>\n",
       "      <td>trace</td>\n",
       "      <td>368967</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>ours</td>\n",
       "      <td>nucleotide</td>\n",
       "      <td>1000</td>\n",
       "      <td>10000</td>\n",
       "      <td>default</td>\n",
       "      <td>223067</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>ours</td>\n",
       "      <td>nucleotide</td>\n",
       "      <td>100</td>\n",
       "      <td>1000</td>\n",
       "      <td>default</td>\n",
       "      <td>24061</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>triple accel</td>\n",
       "      <td>nucleotide</td>\n",
       "      <td>1000</td>\n",
       "      <td>10000</td>\n",
       "      <td>default</td>\n",
       "      <td>8404724</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>triple accel</td>\n",
       "      <td>nucleotide</td>\n",
       "      <td>100</td>\n",
       "      <td>1000</td>\n",
       "      <td>default</td>\n",
       "      <td>24589</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       algorithm    alphabet     k  length property      time\n",
       "0    parasailors     protein  1000   10000  default  52435895\n",
       "1    parasailors     protein   100    1000  default    608499\n",
       "2    parasailors     protein    10     100  default     20155\n",
       "3       rust bio     protein   100    1000  default  15363409\n",
       "4       rust bio     protein    10     100  default    170271\n",
       "5           ours     protein  1000   10000  default    231190\n",
       "6           ours     protein  1000   10000   insert   4913574\n",
       "7           ours     protein  1000   10000    small    220464\n",
       "8           ours     protein  1000   10000    trace   1861712\n",
       "9           ours     protein   100    1000  default     26275\n",
       "10          ours     protein   100    1000   insert     50462\n",
       "11          ours     protein   100    1000    small     23579\n",
       "12          ours     protein   100    1000    trace    514997\n",
       "13          ours     protein    10     100  default      3939\n",
       "14          ours     protein    10     100   insert      4071\n",
       "15          ours     protein    10     100    small      3486\n",
       "16          ours     protein    10     100    trace    368967\n",
       "17          ours  nucleotide  1000   10000  default    223067\n",
       "18          ours  nucleotide   100    1000  default     24061\n",
       "19  triple accel  nucleotide  1000   10000  default   8404724\n",
       "20  triple accel  nucleotide   100    1000  default     24589"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = csv_to_pandas(cleaned, d = \"\\t\", t = \",\")\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:15:53.944797Z",
     "iopub.status.busy": "2023-02-27T11:15:53.944375Z",
     "iopub.status.idle": "2023-02-27T11:15:53.946227Z",
     "shell.execute_reply": "2023-02-27T11:15:53.946673Z"
    }
   },
   "outputs": [],
   "source": [
    "data[\"algorithm property\"] = data[\"algorithm\"] + \" \" + data[\"property\"]\n",
    "data[\"time\"] /= 1000"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Random Protein Sequences Benchmark (AVX2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:15:53.965124Z",
     "iopub.status.busy": "2023-02-27T11:15:53.964727Z",
     "iopub.status.idle": "2023-02-27T11:15:54.728585Z",
     "shell.execute_reply": "2023-02-27T11:15:54.728997Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<div id=\"altair-viz-77ca7af36eef4ff1b52a74487295acf4\"></div>\n",
       "<script type=\"text/javascript\">\n",
       "  (function(spec, embedOpt){\n",
       "    let outputDiv = document.currentScript.previousElementSibling;\n",
       "    if (outputDiv.id !== \"altair-viz-77ca7af36eef4ff1b52a74487295acf4\") {\n",
       "      outputDiv = document.getElementById(\"altair-viz-77ca7af36eef4ff1b52a74487295acf4\");\n",
       "    }\n",
       "    const paths = {\n",
       "      \"vega\": \"https://cdn.jsdelivr.net/npm//vega@5?noext\",\n",
       "      \"vega-lib\": \"https://cdn.jsdelivr.net/npm//vega-lib?noext\",\n",
       "      \"vega-lite\": \"https://cdn.jsdelivr.net/npm//vega-lite@4.8.1?noext\",\n",
       "      \"vega-embed\": \"https://cdn.jsdelivr.net/npm//vega-embed@6?noext\",\n",
       "    };\n",
       "\n",
       "    function loadScript(lib) {\n",
       "      return new Promise(function(resolve, reject) {\n",
       "        var s = document.createElement('script');\n",
       "        s.src = paths[lib];\n",
       "        s.async = true;\n",
       "        s.onload = () => resolve(paths[lib]);\n",
       "        s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
       "        document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "      });\n",
       "    }\n",
       "\n",
       "    function showError(err) {\n",
       "      outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
       "      throw err;\n",
       "    }\n",
       "\n",
       "    function displayChart(vegaEmbed) {\n",
       "      vegaEmbed(outputDiv, spec, embedOpt)\n",
       "        .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
       "    }\n",
       "\n",
       "    if(typeof define === \"function\" && define.amd) {\n",
       "      requirejs.config({paths});\n",
       "      require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
       "    } else if (typeof vegaEmbed === \"function\") {\n",
       "      displayChart(vegaEmbed);\n",
       "    } else {\n",
       "      loadScript(\"vega\")\n",
       "        .then(() => loadScript(\"vega-lite\"))\n",
       "        .then(() => loadScript(\"vega-embed\"))\n",
       "        .catch(showError)\n",
       "        .then(() => displayChart(vegaEmbed));\n",
       "    }\n",
       "  })({\"config\": {\"view\": {\"continuousWidth\": 400, \"continuousHeight\": 300}}, \"data\": {\"url\": \"http://localhost:23517/8ebe34f0c9e797440a5c1e0e4486fa5b.json\"}, \"mark\": {\"type\": \"point\", \"filled\": true, \"opacity\": 1}, \"encoding\": {\"color\": {\"type\": \"nominal\", \"field\": \"length\"}, \"shape\": {\"type\": \"nominal\", \"field\": \"length\"}, \"x\": {\"type\": \"quantitative\", \"axis\": {\"title\": \"time (us)\"}, \"field\": \"time\", \"scale\": {\"domain\": [1, 50000], \"type\": \"log\"}}, \"y\": {\"type\": \"nominal\", \"axis\": {\"grid\": true, \"title\": \"algorithm\"}, \"field\": \"algorithm property\", \"sort\": {\"field\": \"time\"}}}, \"height\": 150, \"transform\": [{\"filter\": \"(datum.alphabet === 'protein')\"}], \"width\": 200, \"$schema\": \"https://vega.github.io/schema/vega-lite/v4.8.1.json\"}, {\"mode\": \"vega-lite\"});\n",
       "</script>"
      ],
      "text/plain": [
       "alt.Chart(...)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = alt.Chart(data).mark_point(opacity = 1, filled = True).encode(\n",
    "    x = alt.X(\"time\", axis = alt.Axis(title = \"time (us)\"), scale = alt.Scale(type = \"log\", domain = [1, 50000])),\n",
    "    y = alt.Y(\"algorithm property\", axis = alt.Axis(title = \"algorithm\", grid = True), sort = alt.EncodingSortField(field = \"time\")),\n",
    "    color = \"length:N\",\n",
    "    shape = \"length:N\"\n",
    ").transform_filter(\n",
    "    datum.alphabet == \"protein\"\n",
    ").properties(\n",
    "    width = 200,\n",
    "    height = 150\n",
    ")\n",
    "save(c, \"random_protein_bench.pdf\")\n",
    "c"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Random DNA Sequences Benchmark (AVX2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:15:54.743436Z",
     "iopub.status.busy": "2023-02-27T11:15:54.743036Z",
     "iopub.status.idle": "2023-02-27T11:15:55.497291Z",
     "shell.execute_reply": "2023-02-27T11:15:55.497737Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<div id=\"altair-viz-2113831fbf8e4fbbb95804b81830acc6\"></div>\n",
       "<script type=\"text/javascript\">\n",
       "  (function(spec, embedOpt){\n",
       "    let outputDiv = document.currentScript.previousElementSibling;\n",
       "    if (outputDiv.id !== \"altair-viz-2113831fbf8e4fbbb95804b81830acc6\") {\n",
       "      outputDiv = document.getElementById(\"altair-viz-2113831fbf8e4fbbb95804b81830acc6\");\n",
       "    }\n",
       "    const paths = {\n",
       "      \"vega\": \"https://cdn.jsdelivr.net/npm//vega@5?noext\",\n",
       "      \"vega-lib\": \"https://cdn.jsdelivr.net/npm//vega-lib?noext\",\n",
       "      \"vega-lite\": \"https://cdn.jsdelivr.net/npm//vega-lite@4.8.1?noext\",\n",
       "      \"vega-embed\": \"https://cdn.jsdelivr.net/npm//vega-embed@6?noext\",\n",
       "    };\n",
       "\n",
       "    function loadScript(lib) {\n",
       "      return new Promise(function(resolve, reject) {\n",
       "        var s = document.createElement('script');\n",
       "        s.src = paths[lib];\n",
       "        s.async = true;\n",
       "        s.onload = () => resolve(paths[lib]);\n",
       "        s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
       "        document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "      });\n",
       "    }\n",
       "\n",
       "    function showError(err) {\n",
       "      outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
       "      throw err;\n",
       "    }\n",
       "\n",
       "    function displayChart(vegaEmbed) {\n",
       "      vegaEmbed(outputDiv, spec, embedOpt)\n",
       "        .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
       "    }\n",
       "\n",
       "    if(typeof define === \"function\" && define.amd) {\n",
       "      requirejs.config({paths});\n",
       "      require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
       "    } else if (typeof vegaEmbed === \"function\") {\n",
       "      displayChart(vegaEmbed);\n",
       "    } else {\n",
       "      loadScript(\"vega\")\n",
       "        .then(() => loadScript(\"vega-lite\"))\n",
       "        .then(() => loadScript(\"vega-embed\"))\n",
       "        .catch(showError)\n",
       "        .then(() => displayChart(vegaEmbed));\n",
       "    }\n",
       "  })({\"config\": {\"view\": {\"continuousWidth\": 400, \"continuousHeight\": 300}}, \"data\": {\"url\": \"http://localhost:23517/8ebe34f0c9e797440a5c1e0e4486fa5b.json\"}, \"mark\": {\"type\": \"point\", \"filled\": true, \"opacity\": 1}, \"encoding\": {\"color\": {\"type\": \"nominal\", \"field\": \"length\", \"scale\": {\"domain\": [100, 1000, 10000]}}, \"shape\": {\"type\": \"nominal\", \"field\": \"length\", \"scale\": {\"domain\": [100, 1000, 10000]}}, \"x\": {\"type\": \"quantitative\", \"axis\": {\"title\": \"time (us)\"}, \"field\": \"time\", \"scale\": {\"domain\": [1, 50000], \"type\": \"log\"}}, \"y\": {\"type\": \"nominal\", \"axis\": {\"grid\": true, \"title\": \"algorithm\"}, \"field\": \"algorithm property\", \"sort\": {\"field\": \"time\"}}}, \"height\": 50, \"transform\": [{\"filter\": \"(datum.alphabet === 'nucleotide')\"}], \"width\": 200, \"$schema\": \"https://vega.github.io/schema/vega-lite/v4.8.1.json\"}, {\"mode\": \"vega-lite\"});\n",
       "</script>"
      ],
      "text/plain": [
       "alt.Chart(...)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = alt.Chart(data).mark_point(opacity = 1, filled = True).encode(\n",
    "    x = alt.X(\"time\", axis = alt.Axis(title = \"time (us)\"), scale = alt.Scale(type = \"log\", domain = [1, 50000])),\n",
    "    y = alt.Y(\"algorithm property\", axis = alt.Axis(title = \"algorithm\", grid = True), sort = alt.EncodingSortField(field = \"time\")),\n",
    "    color = alt.Color(\"length:N\", scale = alt.Scale(domain = [100, 1000, 10000])),\n",
    "    shape = alt.Color(\"length:N\", scale = alt.Scale(domain = [100, 1000, 10000]))\n",
    ").transform_filter(\n",
    "    datum.alphabet == \"nucleotide\"\n",
    ").properties(\n",
    "    width = 200,\n",
    "    height = 50\n",
    ")\n",
    "save(c, \"random_dna_bench.pdf\")\n",
    "c"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Uniclust 30 Data Benchmark"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:15:55.500767Z",
     "iopub.status.busy": "2023-02-27T11:15:55.500333Z",
     "iopub.status.idle": "2023-02-27T11:16:06.938386Z",
     "shell.execute_reply": "2023-02-27T11:16:06.938902Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['# time (s)',\n",
       " 'algorithm, dataset, size, time',\n",
       " 'ours (no trace), uc30, 32-32, 0.056515289',\n",
       " 'ours (no trace), uc30 0.95, 32-32, 0.060549953',\n",
       " 'ours (no trace), uc30, 32-256, 0.089667067',\n",
       " 'ours (no trace), uc30 0.95, 32-256, 0.07712594',\n",
       " 'ours (no trace), uc30, 256-256, 0.199199121',\n",
       " 'ours (no trace), uc30 0.95, 256-256, 0.22163839',\n",
       " 'ours (trace), uc30, 32-256, 0.168939332',\n",
       " 'ours (trace), uc30 0.95, 32-256, 0.150488372',\n",
       " 'parasail, uc30, full, 0.885421801',\n",
       " 'parasail, uc30 0.95, full, 1.028783795']"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "output = !cd .. && cargo run --example uc_bench --release --features simd_avx2 --quiet\n",
    "output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:16:06.942041Z",
     "iopub.status.busy": "2023-02-27T11:16:06.941574Z",
     "iopub.status.idle": "2023-02-27T11:16:06.950831Z",
     "shell.execute_reply": "2023-02-27T11:16:06.951174Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>algorithm</th>\n",
       "      <th>dataset</th>\n",
       "      <th>size</th>\n",
       "      <th>time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ours (no trace)</td>\n",
       "      <td>uc30</td>\n",
       "      <td>32-32</td>\n",
       "      <td>0.056515</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ours (no trace)</td>\n",
       "      <td>uc30 0.95</td>\n",
       "      <td>32-32</td>\n",
       "      <td>0.060550</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ours (no trace)</td>\n",
       "      <td>uc30</td>\n",
       "      <td>32-256</td>\n",
       "      <td>0.089667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ours (no trace)</td>\n",
       "      <td>uc30 0.95</td>\n",
       "      <td>32-256</td>\n",
       "      <td>0.077126</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ours (no trace)</td>\n",
       "      <td>uc30</td>\n",
       "      <td>256-256</td>\n",
       "      <td>0.199199</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ours (no trace)</td>\n",
       "      <td>uc30 0.95</td>\n",
       "      <td>256-256</td>\n",
       "      <td>0.221638</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>ours (trace)</td>\n",
       "      <td>uc30</td>\n",
       "      <td>32-256</td>\n",
       "      <td>0.168939</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>ours (trace)</td>\n",
       "      <td>uc30 0.95</td>\n",
       "      <td>32-256</td>\n",
       "      <td>0.150488</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>parasail</td>\n",
       "      <td>uc30</td>\n",
       "      <td>full</td>\n",
       "      <td>0.885422</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>parasail</td>\n",
       "      <td>uc30 0.95</td>\n",
       "      <td>full</td>\n",
       "      <td>1.028784</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         algorithm    dataset     size      time\n",
       "0  ours (no trace)       uc30    32-32  0.056515\n",
       "1  ours (no trace)  uc30 0.95    32-32  0.060550\n",
       "2  ours (no trace)       uc30   32-256  0.089667\n",
       "3  ours (no trace)  uc30 0.95   32-256  0.077126\n",
       "4  ours (no trace)       uc30  256-256  0.199199\n",
       "5  ours (no trace)  uc30 0.95  256-256  0.221638\n",
       "6     ours (trace)       uc30   32-256  0.168939\n",
       "7     ours (trace)  uc30 0.95   32-256  0.150488\n",
       "8         parasail       uc30     full  0.885422\n",
       "9         parasail  uc30 0.95     full  1.028784"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = csv_to_pandas(output)\n",
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Uniclust30 Benchmark (AVX2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:16:06.974028Z",
     "iopub.status.busy": "2023-02-27T11:16:06.973627Z",
     "iopub.status.idle": "2023-02-27T11:16:07.745338Z",
     "shell.execute_reply": "2023-02-27T11:16:07.745757Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<div id=\"altair-viz-f56eb0fc4217424b92785ad6cda1c57a\"></div>\n",
       "<script type=\"text/javascript\">\n",
       "  (function(spec, embedOpt){\n",
       "    let outputDiv = document.currentScript.previousElementSibling;\n",
       "    if (outputDiv.id !== \"altair-viz-f56eb0fc4217424b92785ad6cda1c57a\") {\n",
       "      outputDiv = document.getElementById(\"altair-viz-f56eb0fc4217424b92785ad6cda1c57a\");\n",
       "    }\n",
       "    const paths = {\n",
       "      \"vega\": \"https://cdn.jsdelivr.net/npm//vega@5?noext\",\n",
       "      \"vega-lib\": \"https://cdn.jsdelivr.net/npm//vega-lib?noext\",\n",
       "      \"vega-lite\": \"https://cdn.jsdelivr.net/npm//vega-lite@4.8.1?noext\",\n",
       "      \"vega-embed\": \"https://cdn.jsdelivr.net/npm//vega-embed@6?noext\",\n",
       "    };\n",
       "\n",
       "    function loadScript(lib) {\n",
       "      return new Promise(function(resolve, reject) {\n",
       "        var s = document.createElement('script');\n",
       "        s.src = paths[lib];\n",
       "        s.async = true;\n",
       "        s.onload = () => resolve(paths[lib]);\n",
       "        s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
       "        document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "      });\n",
       "    }\n",
       "\n",
       "    function showError(err) {\n",
       "      outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
       "      throw err;\n",
       "    }\n",
       "\n",
       "    function displayChart(vegaEmbed) {\n",
       "      vegaEmbed(outputDiv, spec, embedOpt)\n",
       "        .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
       "    }\n",
       "\n",
       "    if(typeof define === \"function\" && define.amd) {\n",
       "      requirejs.config({paths});\n",
       "      require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
       "    } else if (typeof vegaEmbed === \"function\") {\n",
       "      displayChart(vegaEmbed);\n",
       "    } else {\n",
       "      loadScript(\"vega\")\n",
       "        .then(() => loadScript(\"vega-lite\"))\n",
       "        .then(() => loadScript(\"vega-embed\"))\n",
       "        .catch(showError)\n",
       "        .then(() => displayChart(vegaEmbed));\n",
       "    }\n",
       "  })({\"config\": {\"view\": {\"continuousWidth\": 400, \"continuousHeight\": 300}, \"range\": {\"category\": {\"scheme\": \"dark2\"}}}, \"data\": {\"url\": \"http://localhost:23517/a7d2c1949187a0a79a029bdb332097d8.json\"}, \"facet\": {\"column\": {\"type\": \"nominal\", \"field\": \"dataset\", \"header\": {\"orient\": \"bottom\"}}}, \"spec\": {\"layer\": [{\"mark\": \"bar\", \"encoding\": {\"color\": {\"type\": \"nominal\", \"field\": \"algorithm\"}, \"x\": {\"type\": \"nominal\", \"axis\": null, \"field\": \"algorithm\"}, \"y\": {\"type\": \"quantitative\", \"axis\": {\"title\": \"time (s)\"}, \"field\": \"time\", \"scale\": {\"domain\": [0.0, 1.0]}}}, \"transform\": [{\"filter\": \"((datum.size === '32-256') || (datum.algorithm === 'parasail'))\"}]}, {\"mark\": {\"type\": \"text\", \"dy\": -4, \"size\": 8}, \"encoding\": {\"color\": {\"value\": \"black\"}, \"text\": {\"type\": \"quantitative\", \"field\": \"time\", \"format\": \".2f\"}, \"x\": {\"type\": \"nominal\", \"axis\": null, \"field\": \"algorithm\"}, \"y\": {\"type\": \"quantitative\", \"axis\": {\"title\": \"time (s)\"}, \"field\": \"time\", \"scale\": {\"domain\": [0.0, 1.0]}}}, \"transform\": [{\"filter\": \"((datum.size === '32-256') || (datum.algorithm === 'parasail'))\"}]}], \"height\": 100, \"width\": 50}, \"$schema\": \"https://vega.github.io/schema/vega-lite/v4.8.1.json\"}, {\"mode\": \"vega-lite\"});\n",
       "</script>"
      ],
      "text/plain": [
       "alt.FacetChart(...)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = alt.Chart(data).mark_bar().encode(\n",
    "    x = alt.X(\"algorithm\", axis = None),\n",
    "    y = alt.Y(\"time\", axis = alt.Axis(title = \"time (s)\"), scale = alt.Scale(domain = [0.0, 1.0])),\n",
    "    color = \"algorithm\"\n",
    ").transform_filter(\n",
    "    (datum.size == \"32-256\") | (datum.algorithm == \"parasail\")\n",
    ")\n",
    "t = c.mark_text(dy = -4, size = 8).encode(text = alt.Text(\"time\", format = \".2f\"), color = alt.value(\"black\"))\n",
    "c = (c + t).properties(\n",
    "    width = 50,\n",
    "    height = 100\n",
    ").facet(\n",
    "    column = alt.Column(\"dataset\", header = alt.Header(orient = \"bottom\")),\n",
    ").configure_range(\n",
    "    category = {\"scheme\": \"dark2\"}\n",
    ")\n",
    "save(c, \"uniclust30_bench.pdf\")\n",
    "c"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Uniclust30 Block Size Benchmark (AVX2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:16:07.764443Z",
     "iopub.status.busy": "2023-02-27T11:16:07.764039Z",
     "iopub.status.idle": "2023-02-27T11:16:08.538727Z",
     "shell.execute_reply": "2023-02-27T11:16:08.539147Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<div id=\"altair-viz-3a6a391d2f9a4587bb55dd5eee1075aa\"></div>\n",
       "<script type=\"text/javascript\">\n",
       "  (function(spec, embedOpt){\n",
       "    let outputDiv = document.currentScript.previousElementSibling;\n",
       "    if (outputDiv.id !== \"altair-viz-3a6a391d2f9a4587bb55dd5eee1075aa\") {\n",
       "      outputDiv = document.getElementById(\"altair-viz-3a6a391d2f9a4587bb55dd5eee1075aa\");\n",
       "    }\n",
       "    const paths = {\n",
       "      \"vega\": \"https://cdn.jsdelivr.net/npm//vega@5?noext\",\n",
       "      \"vega-lib\": \"https://cdn.jsdelivr.net/npm//vega-lib?noext\",\n",
       "      \"vega-lite\": \"https://cdn.jsdelivr.net/npm//vega-lite@4.8.1?noext\",\n",
       "      \"vega-embed\": \"https://cdn.jsdelivr.net/npm//vega-embed@6?noext\",\n",
       "    };\n",
       "\n",
       "    function loadScript(lib) {\n",
       "      return new Promise(function(resolve, reject) {\n",
       "        var s = document.createElement('script');\n",
       "        s.src = paths[lib];\n",
       "        s.async = true;\n",
       "        s.onload = () => resolve(paths[lib]);\n",
       "        s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
       "        document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "      });\n",
       "    }\n",
       "\n",
       "    function showError(err) {\n",
       "      outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
       "      throw err;\n",
       "    }\n",
       "\n",
       "    function displayChart(vegaEmbed) {\n",
       "      vegaEmbed(outputDiv, spec, embedOpt)\n",
       "        .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
       "    }\n",
       "\n",
       "    if(typeof define === \"function\" && define.amd) {\n",
       "      requirejs.config({paths});\n",
       "      require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
       "    } else if (typeof vegaEmbed === \"function\") {\n",
       "      displayChart(vegaEmbed);\n",
       "    } else {\n",
       "      loadScript(\"vega\")\n",
       "        .then(() => loadScript(\"vega-lite\"))\n",
       "        .then(() => loadScript(\"vega-embed\"))\n",
       "        .catch(showError)\n",
       "        .then(() => displayChart(vegaEmbed));\n",
       "    }\n",
       "  })({\"config\": {\"view\": {\"continuousWidth\": 400, \"continuousHeight\": 300}}, \"data\": {\"url\": \"http://localhost:23517/a7d2c1949187a0a79a029bdb332097d8.json\"}, \"facet\": {\"column\": {\"type\": \"nominal\", \"field\": \"dataset\", \"header\": {\"orient\": \"bottom\"}}}, \"spec\": {\"layer\": [{\"mark\": \"bar\", \"encoding\": {\"color\": {\"type\": \"nominal\", \"field\": \"size\", \"sort\": [\"32-32\", \"32-256\", \"256-256\"], \"title\": \"block size\"}, \"x\": {\"type\": \"nominal\", \"axis\": null, \"field\": \"size\", \"sort\": [\"32-32\", \"32-256\", \"256-256\"]}, \"y\": {\"type\": \"quantitative\", \"axis\": {\"title\": \"time (s)\"}, \"field\": \"time\", \"scale\": {\"domain\": [0.0, 1.0]}}}, \"transform\": [{\"filter\": \"(datum.algorithm === 'ours (no trace)')\"}]}, {\"mark\": {\"type\": \"text\", \"dy\": -4, \"size\": 8}, \"encoding\": {\"color\": {\"value\": \"black\"}, \"text\": {\"type\": \"quantitative\", \"field\": \"time\", \"format\": \".2f\"}, \"x\": {\"type\": \"nominal\", \"axis\": null, \"field\": \"size\", \"sort\": [\"32-32\", \"32-256\", \"256-256\"]}, \"y\": {\"type\": \"quantitative\", \"axis\": {\"title\": \"time (s)\"}, \"field\": \"time\", \"scale\": {\"domain\": [0.0, 1.0]}}}, \"transform\": [{\"filter\": \"(datum.algorithm === 'ours (no trace)')\"}]}], \"height\": 100, \"width\": 50}, \"$schema\": \"https://vega.github.io/schema/vega-lite/v4.8.1.json\"}, {\"mode\": \"vega-lite\"});\n",
       "</script>"
      ],
      "text/plain": [
       "alt.FacetChart(...)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = alt.Chart(data).mark_bar().encode(\n",
    "    x = alt.X(\"size\", axis = None, sort = [\"32-32\", \"32-256\", \"256-256\"]),\n",
    "    y = alt.Y(\"time\", axis = alt.Axis(title = \"time (s)\"), scale = alt.Scale(domain = [0.0, 1.0])),\n",
    "    color = alt.Color(\"size\", title = \"block size\", sort = [\"32-32\", \"32-256\", \"256-256\"])\n",
    ").transform_filter(\n",
    "    datum.algorithm == \"ours (no trace)\"\n",
    ")\n",
    "t = c.mark_text(dy = -4, size = 8).encode(text = alt.Text(\"time\", format = \".2f\"), color = alt.value(\"black\"))\n",
    "c = (c + t).properties(\n",
    "    width = 50,\n",
    "    height = 100\n",
    ").facet(\n",
    "    column = alt.Column(\"dataset\", header = alt.Header(orient = \"bottom\")),\n",
    ")\n",
    "save(c, \"uniclust30_size_bench.pdf\")\n",
    "c"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## DNA Global Alignment Benchmark"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:16:08.542462Z",
     "iopub.status.busy": "2023-02-27T11:16:08.542030Z",
     "iopub.status.idle": "2023-02-27T11:42:45.389836Z",
     "shell.execute_reply": "2023-02-27T11:42:45.390335Z"
    },
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['# time (s)',\n",
       " 'dataset, algorithm, time',\n",
       " 'illumina, ours (1%-1%), 0.19954773599994785',\n",
       " 'illumina, ours (1%-10%), 0.21103766700000928',\n",
       " 'illumina, edlib, 0.3688567379999959',\n",
       " 'illumina, ksw_extz2_sse (1%), 0.5450279550000086',\n",
       " 'illumina, ksw_extz2_sse (10%), 0.5442524660000194',\n",
       " 'illumina, wfa2, 0.07222540399997783',\n",
       " 'illumina, wfa2 adaptive, 0.07643134800001018',\n",
       " 'illumina, parasail, 1.905899847999988',\n",
       " 'nanopore 1kbp, ours (1%-1%), 0.20423522500000035',\n",
       " 'nanopore 1kbp, ours (1%-10%), 0.2545604999999995',\n",
       " 'nanopore 1kbp, edlib, 0.361402042999999',\n",
       " 'nanopore 1kbp, ksw_extz2_sse (1%), 0.5809077849999988',\n",
       " 'nanopore 1kbp, ksw_extz2_sse (10%), 1.2340126780000036',\n",
       " 'nanopore 1kbp, wfa2, 1.182402372000001',\n",
       " 'nanopore 1kbp, wfa2 adaptive, 0.9811043799999979',\n",
       " 'nanopore 1kbp, parasail, 3.922164622000011',\n",
       " 'nanopore <10kbp, ours (1%-1%), 0.7581100459999974',\n",
       " 'nanopore <10kbp, ours (1%-10%), 1.082943893999997',\n",
       " 'nanopore <10kbp, edlib, 1.2777344540000006',\n",
       " 'nanopore <10kbp, ksw_extz2_sse (1%), 1.6990866190000016',\n",
       " 'nanopore <10kbp, ksw_extz2_sse (10%), 10.586113880999992',\n",
       " 'nanopore <10kbp, wfa2, 18.751342348000023',\n",
       " 'nanopore <10kbp, wfa2 adaptive, 6.086742439000021',\n",
       " 'nanopore <10kbp, parasail, 33.93674228799994',\n",
       " 'nanopore <50kbp, ours (1%-1%), 16.517385590999943',\n",
       " 'nanopore <50kbp, ours (1%-10%), 28.693855664999983',\n",
       " 'nanopore <50kbp, edlib, 21.42700936800003',\n",
       " 'nanopore <50kbp, ksw_extz2_sse (1%), 32.73222982999999',\n",
       " 'nanopore <50kbp, ksw_extz2_sse (10%), 298.4867550620014',\n",
       " 'nanopore <50kbp, wfa2, 739.9792715350003',\n",
       " 'nanopore <50kbp, wfa2 adaptive, 166.71527254399973']"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "output = !cd .. && cargo run --example nanopore_bench_global --release --features simd_avx2 --quiet\n",
    "output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:42:45.393704Z",
     "iopub.status.busy": "2023-02-27T11:42:45.393201Z",
     "iopub.status.idle": "2023-02-27T11:42:45.403465Z",
     "shell.execute_reply": "2023-02-27T11:42:45.403961Z"
    },
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>dataset</th>\n",
       "      <th>algorithm</th>\n",
       "      <th>time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>illumina</td>\n",
       "      <td>ours (1%-1%)</td>\n",
       "      <td>0.199548</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>illumina</td>\n",
       "      <td>ours (1%-10%)</td>\n",
       "      <td>0.211038</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>illumina</td>\n",
       "      <td>edlib</td>\n",
       "      <td>0.368857</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>illumina</td>\n",
       "      <td>ksw_extz2_sse (1%)</td>\n",
       "      <td>0.545028</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>illumina</td>\n",
       "      <td>ksw_extz2_sse (10%)</td>\n",
       "      <td>0.544252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>illumina</td>\n",
       "      <td>wfa2</td>\n",
       "      <td>0.072225</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>illumina</td>\n",
       "      <td>wfa2 adaptive</td>\n",
       "      <td>0.076431</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>illumina</td>\n",
       "      <td>parasail</td>\n",
       "      <td>1.905900</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>nanopore 1kbp</td>\n",
       "      <td>ours (1%-1%)</td>\n",
       "      <td>0.204235</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>nanopore 1kbp</td>\n",
       "      <td>ours (1%-10%)</td>\n",
       "      <td>0.254560</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>nanopore 1kbp</td>\n",
       "      <td>edlib</td>\n",
       "      <td>0.361402</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>nanopore 1kbp</td>\n",
       "      <td>ksw_extz2_sse (1%)</td>\n",
       "      <td>0.580908</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>nanopore 1kbp</td>\n",
       "      <td>ksw_extz2_sse (10%)</td>\n",
       "      <td>1.234013</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>nanopore 1kbp</td>\n",
       "      <td>wfa2</td>\n",
       "      <td>1.182402</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>nanopore 1kbp</td>\n",
       "      <td>wfa2 adaptive</td>\n",
       "      <td>0.981104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>nanopore 1kbp</td>\n",
       "      <td>parasail</td>\n",
       "      <td>3.922165</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>nanopore &lt;10kbp</td>\n",
       "      <td>ours (1%-1%)</td>\n",
       "      <td>0.758110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>nanopore &lt;10kbp</td>\n",
       "      <td>ours (1%-10%)</td>\n",
       "      <td>1.082944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>nanopore &lt;10kbp</td>\n",
       "      <td>edlib</td>\n",
       "      <td>1.277734</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>nanopore &lt;10kbp</td>\n",
       "      <td>ksw_extz2_sse (1%)</td>\n",
       "      <td>1.699087</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>nanopore &lt;10kbp</td>\n",
       "      <td>ksw_extz2_sse (10%)</td>\n",
       "      <td>10.586114</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>nanopore &lt;10kbp</td>\n",
       "      <td>wfa2</td>\n",
       "      <td>18.751342</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>nanopore &lt;10kbp</td>\n",
       "      <td>wfa2 adaptive</td>\n",
       "      <td>6.086742</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>nanopore &lt;10kbp</td>\n",
       "      <td>parasail</td>\n",
       "      <td>33.936742</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>nanopore &lt;50kbp</td>\n",
       "      <td>ours (1%-1%)</td>\n",
       "      <td>16.517386</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>nanopore &lt;50kbp</td>\n",
       "      <td>ours (1%-10%)</td>\n",
       "      <td>28.693856</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>nanopore &lt;50kbp</td>\n",
       "      <td>edlib</td>\n",
       "      <td>21.427009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>nanopore &lt;50kbp</td>\n",
       "      <td>ksw_extz2_sse (1%)</td>\n",
       "      <td>32.732230</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>nanopore &lt;50kbp</td>\n",
       "      <td>ksw_extz2_sse (10%)</td>\n",
       "      <td>298.486755</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>nanopore &lt;50kbp</td>\n",
       "      <td>wfa2</td>\n",
       "      <td>739.979272</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>nanopore &lt;50kbp</td>\n",
       "      <td>wfa2 adaptive</td>\n",
       "      <td>166.715273</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            dataset            algorithm        time\n",
       "0          illumina         ours (1%-1%)    0.199548\n",
       "1          illumina        ours (1%-10%)    0.211038\n",
       "2          illumina                edlib    0.368857\n",
       "3          illumina   ksw_extz2_sse (1%)    0.545028\n",
       "4          illumina  ksw_extz2_sse (10%)    0.544252\n",
       "5          illumina                 wfa2    0.072225\n",
       "6          illumina        wfa2 adaptive    0.076431\n",
       "7          illumina             parasail    1.905900\n",
       "8     nanopore 1kbp         ours (1%-1%)    0.204235\n",
       "9     nanopore 1kbp        ours (1%-10%)    0.254560\n",
       "10    nanopore 1kbp                edlib    0.361402\n",
       "11    nanopore 1kbp   ksw_extz2_sse (1%)    0.580908\n",
       "12    nanopore 1kbp  ksw_extz2_sse (10%)    1.234013\n",
       "13    nanopore 1kbp                 wfa2    1.182402\n",
       "14    nanopore 1kbp        wfa2 adaptive    0.981104\n",
       "15    nanopore 1kbp             parasail    3.922165\n",
       "16  nanopore <10kbp         ours (1%-1%)    0.758110\n",
       "17  nanopore <10kbp        ours (1%-10%)    1.082944\n",
       "18  nanopore <10kbp                edlib    1.277734\n",
       "19  nanopore <10kbp   ksw_extz2_sse (1%)    1.699087\n",
       "20  nanopore <10kbp  ksw_extz2_sse (10%)   10.586114\n",
       "21  nanopore <10kbp                 wfa2   18.751342\n",
       "22  nanopore <10kbp        wfa2 adaptive    6.086742\n",
       "23  nanopore <10kbp             parasail   33.936742\n",
       "24  nanopore <50kbp         ours (1%-1%)   16.517386\n",
       "25  nanopore <50kbp        ours (1%-10%)   28.693856\n",
       "26  nanopore <50kbp                edlib   21.427009\n",
       "27  nanopore <50kbp   ksw_extz2_sse (1%)   32.732230\n",
       "28  nanopore <50kbp  ksw_extz2_sse (10%)  298.486755\n",
       "29  nanopore <50kbp                 wfa2  739.979272\n",
       "30  nanopore <50kbp        wfa2 adaptive  166.715273"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = csv_to_pandas(output)\n",
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "DNA Global Alignment Benchmark (AVX2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:42:45.424787Z",
     "iopub.status.busy": "2023-02-27T11:42:45.424315Z",
     "iopub.status.idle": "2023-02-27T11:42:46.215270Z",
     "shell.execute_reply": "2023-02-27T11:42:46.215707Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<div id=\"altair-viz-fc3e1e5f30ee4fc28ee88d3d10bcc710\"></div>\n",
       "<script type=\"text/javascript\">\n",
       "  (function(spec, embedOpt){\n",
       "    let outputDiv = document.currentScript.previousElementSibling;\n",
       "    if (outputDiv.id !== \"altair-viz-fc3e1e5f30ee4fc28ee88d3d10bcc710\") {\n",
       "      outputDiv = document.getElementById(\"altair-viz-fc3e1e5f30ee4fc28ee88d3d10bcc710\");\n",
       "    }\n",
       "    const paths = {\n",
       "      \"vega\": \"https://cdn.jsdelivr.net/npm//vega@5?noext\",\n",
       "      \"vega-lib\": \"https://cdn.jsdelivr.net/npm//vega-lib?noext\",\n",
       "      \"vega-lite\": \"https://cdn.jsdelivr.net/npm//vega-lite@4.8.1?noext\",\n",
       "      \"vega-embed\": \"https://cdn.jsdelivr.net/npm//vega-embed@6?noext\",\n",
       "    };\n",
       "\n",
       "    function loadScript(lib) {\n",
       "      return new Promise(function(resolve, reject) {\n",
       "        var s = document.createElement('script');\n",
       "        s.src = paths[lib];\n",
       "        s.async = true;\n",
       "        s.onload = () => resolve(paths[lib]);\n",
       "        s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
       "        document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "      });\n",
       "    }\n",
       "\n",
       "    function showError(err) {\n",
       "      outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
       "      throw err;\n",
       "    }\n",
       "\n",
       "    function displayChart(vegaEmbed) {\n",
       "      vegaEmbed(outputDiv, spec, embedOpt)\n",
       "        .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
       "    }\n",
       "\n",
       "    if(typeof define === \"function\" && define.amd) {\n",
       "      requirejs.config({paths});\n",
       "      require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
       "    } else if (typeof vegaEmbed === \"function\") {\n",
       "      displayChart(vegaEmbed);\n",
       "    } else {\n",
       "      loadScript(\"vega\")\n",
       "        .then(() => loadScript(\"vega-lite\"))\n",
       "        .then(() => loadScript(\"vega-embed\"))\n",
       "        .catch(showError)\n",
       "        .then(() => displayChart(vegaEmbed));\n",
       "    }\n",
       "  })({\"config\": {\"view\": {\"continuousWidth\": 400, \"continuousHeight\": 300}, \"axisY\": {\"labelAlign\": \"left\", \"labelPadding\": 18}}, \"data\": {\"url\": \"http://localhost:23517/30877b000c79270277c100fe9c450921.json\"}, \"facet\": {\"type\": \"nominal\", \"field\": \"dataset\", \"header\": {\"orient\": \"top\"}, \"title\": null}, \"spec\": {\"layer\": [{\"mark\": \"bar\", \"encoding\": {\"color\": {\"type\": \"nominal\", \"field\": \"algorithm\", \"legend\": null}, \"x\": {\"type\": \"nominal\", \"field\": \"algorithm\", \"sort\": [\"ours (1%-1%)\", \"ours (1%-10%)\", \"edlib\", \"ksw_extz2_sse (1%)\", \"ksw_extz2_sse (10%)\", \"wfa2\", \"wfa2 adaptive\", \"parasail\"], \"title\": null}, \"y\": {\"type\": \"quantitative\", \"axis\": {\"title\": \"time (s)\"}, \"field\": \"time\"}}}, {\"mark\": {\"type\": \"text\", \"dy\": -4, \"size\": 8}, \"encoding\": {\"color\": {\"value\": \"black\"}, \"text\": {\"type\": \"quantitative\", \"field\": \"time\", \"format\": \".2f\"}, \"x\": {\"type\": \"nominal\", \"field\": \"algorithm\", \"sort\": [\"ours (1%-1%)\", \"ours (1%-10%)\", \"edlib\", \"ksw_extz2_sse (1%)\", \"ksw_extz2_sse (10%)\", \"wfa2\", \"wfa2 adaptive\", \"parasail\"], \"title\": null}, \"y\": {\"type\": \"quantitative\", \"axis\": {\"title\": \"time (s)\"}, \"field\": \"time\"}}}], \"height\": 140, \"width\": 140}, \"columns\": 2, \"resolve\": {\"scale\": {\"y\": \"independent\"}}, \"$schema\": \"https://vega.github.io/schema/vega-lite/v4.8.1.json\"}, {\"mode\": \"vega-lite\"});\n",
       "</script>"
      ],
      "text/plain": [
       "alt.FacetChart(...)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "algos = [\"ours (1%-1%)\", \"ours (1%-10%)\", \"edlib\", \"ksw_extz2_sse (1%)\", \"ksw_extz2_sse (10%)\", \"wfa2\", \"wfa2 adaptive\", \"parasail\"]\n",
    "c = alt.Chart(data).mark_bar().encode(\n",
    "    x = alt.X(\"algorithm\", sort = algos, title = None),\n",
    "    y = alt.Y(\"time\", axis = alt.Axis(title = \"time (s)\")),\n",
    "    color = alt.Color(\"algorithm\", legend = None)\n",
    ")\n",
    "t = c.mark_text(dy = -4, size = 8).encode(text = alt.Text(\"time\", format = \".2f\"), color = alt.value(\"black\"))\n",
    "c = (c + t).properties(\n",
    "    width = 140,\n",
    "    height = 140\n",
    ").facet(\n",
    "    facet = alt.Facet(\"dataset\", title = None, header = alt.Header(orient = \"top\")),\n",
    "    columns = 2\n",
    ").resolve_scale(\n",
    "    y = \"independent\"\n",
    ").configure_axisY(\n",
    "    labelPadding = 18,\n",
    "    labelAlign = \"left\"\n",
    ")\n",
    "save(c, \"dna_global_bench.pdf\")\n",
    "c"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Nanopore Data Benchmark Setup\n",
    "\n",
    "To run the benchmarks below, you need to clone the following repos, place them in the same directory where this repo (block aligner) is located, and follow their setup instructions:\n",
    "* [diff-bench-paper](https://github.com/Daniel-Liu-c0deb0t/diff-bench-paper)\n",
    "* [adaptivebandbench](https://github.com/Daniel-Liu-c0deb0t/adaptivebandbench)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Nanopore Data Benchmark"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:42:46.218784Z",
     "iopub.status.busy": "2023-02-27T11:42:46.218396Z",
     "iopub.status.idle": "2023-02-27T11:43:12.923815Z",
     "shell.execute_reply": "2023-02-27T11:43:12.924373Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['# time (s)',\n",
       " 'algorithm, dataset, time',\n",
       " 'ours (no trace 32-32), nanopore 25kbp, 1.033478184',\n",
       " 'ours (no trace 32-32), random, 2.550499957',\n",
       " 'ours (trace 32-32), nanopore 25kbp, 1.412760824',\n",
       " 'ours (trace 32-32), random, 3.400294701',\n",
       " 'ours (trace 32-64), nanopore 25kbp, 1.6694597629999999',\n",
       " 'ours (trace 32-64), random, 3.5342896550000003']"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "output = !cd .. && cargo run --example nanopore_bench --release --features simd_avx2 --quiet\n",
    "output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:43:12.927699Z",
     "iopub.status.busy": "2023-02-27T11:43:12.927222Z",
     "iopub.status.idle": "2023-02-27T11:43:12.934820Z",
     "shell.execute_reply": "2023-02-27T11:43:12.935315Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>algorithm</th>\n",
       "      <th>dataset</th>\n",
       "      <th>time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ours (no trace 32-32)</td>\n",
       "      <td>nanopore 25kbp</td>\n",
       "      <td>1.033478</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ours (no trace 32-32)</td>\n",
       "      <td>random</td>\n",
       "      <td>2.550500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ours (trace 32-32)</td>\n",
       "      <td>nanopore 25kbp</td>\n",
       "      <td>1.412761</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ours (trace 32-32)</td>\n",
       "      <td>random</td>\n",
       "      <td>3.400295</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ours (trace 32-64)</td>\n",
       "      <td>nanopore 25kbp</td>\n",
       "      <td>1.669460</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ours (trace 32-64)</td>\n",
       "      <td>random</td>\n",
       "      <td>3.534290</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               algorithm         dataset      time\n",
       "0  ours (no trace 32-32)  nanopore 25kbp  1.033478\n",
       "1  ours (no trace 32-32)          random  2.550500\n",
       "2     ours (trace 32-32)  nanopore 25kbp  1.412761\n",
       "3     ours (trace 32-32)          random  3.400295\n",
       "4     ours (trace 32-64)  nanopore 25kbp  1.669460\n",
       "5     ours (trace 32-64)          random  3.534290"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = csv_to_pandas(output)\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:43:12.939354Z",
     "iopub.status.busy": "2023-02-27T11:43:12.938867Z",
     "iopub.status.idle": "2023-02-27T11:46:20.791973Z",
     "shell.execute_reply": "2023-02-27T11:46:20.792429Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['algorithm\\tfill time\\ttrace time\\tconvert time\\ttotal time\\tscore\\tfail',\n",
       " 'editdist\\t476567000\\t170629000\\t67690000\\t714886000\\t6880489\\t0',\n",
       " 'non-diff\\t681717000\\t270098000\\t61707000\\t1013522000\\t27124786\\t52',\n",
       " 'diff-raw\\t634119000\\t213761000\\t64883000\\t912763000\\t27291141\\t32',\n",
       " 'libgaba\\t452611000\\t157111000\\t32888000\\t642610000\\t27121546\\t53',\n",
       " 'edlib\\t28046347000\\t19390997000\\t106224000\\t47543568000\\t37\\t0',\n",
       " 'seqan\\t90098655000\\t0\\t0\\t90098655000\\t0\\t0']"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "output2 = !cd ../../diff-bench-paper/supplementary_data/benchmark_codes && ./custom_bench.sh\n",
    "\n",
    "for i, o in enumerate(output2):\n",
    "    if o.startswith(\"cells(\"):\n",
    "        break\n",
    "output2 = output2[i + 1:]\n",
    "\n",
    "output2.insert(0, \"algorithm\\tfill time\\ttrace time\\tconvert time\\ttotal time\\tscore\\tfail\")\n",
    "output2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:46:20.795582Z",
     "iopub.status.busy": "2023-02-27T11:46:20.795183Z",
     "iopub.status.idle": "2023-02-27T11:46:20.803300Z",
     "shell.execute_reply": "2023-02-27T11:46:20.803710Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>algorithm</th>\n",
       "      <th>fill time</th>\n",
       "      <th>trace time</th>\n",
       "      <th>convert time</th>\n",
       "      <th>total time</th>\n",
       "      <th>score</th>\n",
       "      <th>fail</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>editdist</td>\n",
       "      <td>476567000</td>\n",
       "      <td>170629000</td>\n",
       "      <td>67690000</td>\n",
       "      <td>714886000</td>\n",
       "      <td>6880489</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>non-diff</td>\n",
       "      <td>681717000</td>\n",
       "      <td>270098000</td>\n",
       "      <td>61707000</td>\n",
       "      <td>1013522000</td>\n",
       "      <td>27124786</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>diff-raw</td>\n",
       "      <td>634119000</td>\n",
       "      <td>213761000</td>\n",
       "      <td>64883000</td>\n",
       "      <td>912763000</td>\n",
       "      <td>27291141</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>libgaba</td>\n",
       "      <td>452611000</td>\n",
       "      <td>157111000</td>\n",
       "      <td>32888000</td>\n",
       "      <td>642610000</td>\n",
       "      <td>27121546</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>edlib</td>\n",
       "      <td>28046347000</td>\n",
       "      <td>19390997000</td>\n",
       "      <td>106224000</td>\n",
       "      <td>47543568000</td>\n",
       "      <td>37</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>seqan</td>\n",
       "      <td>90098655000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>90098655000</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  algorithm    fill time   trace time  convert time   total time     score  \\\n",
       "0  editdist    476567000    170629000      67690000    714886000   6880489   \n",
       "1  non-diff    681717000    270098000      61707000   1013522000  27124786   \n",
       "2  diff-raw    634119000    213761000      64883000    912763000  27291141   \n",
       "3   libgaba    452611000    157111000      32888000    642610000  27121546   \n",
       "4     edlib  28046347000  19390997000     106224000  47543568000        37   \n",
       "5     seqan  90098655000            0             0  90098655000         0   \n",
       "\n",
       "   fail  \n",
       "0     0  \n",
       "1    52  \n",
       "2    32  \n",
       "3    53  \n",
       "4     0  \n",
       "5     0  "
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data2 = csv_to_pandas(output2, d = \"\\t\")\n",
    "data2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:46:20.810251Z",
     "iopub.status.busy": "2023-02-27T11:46:20.809714Z",
     "iopub.status.idle": "2023-02-27T11:46:20.811935Z",
     "shell.execute_reply": "2023-02-27T11:46:20.812354Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>algorithm</th>\n",
       "      <th>time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>editdist</td>\n",
       "      <td>0.476567</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>non-diff</td>\n",
       "      <td>0.681717</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>diff-raw</td>\n",
       "      <td>0.634119</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>libgaba</td>\n",
       "      <td>0.452611</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>edlib</td>\n",
       "      <td>28.046347</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>seqan</td>\n",
       "      <td>90.098655</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  algorithm       time\n",
       "0  editdist   0.476567\n",
       "1  non-diff   0.681717\n",
       "2  diff-raw   0.634119\n",
       "3   libgaba   0.452611\n",
       "4     edlib  28.046347\n",
       "5     seqan  90.098655"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cleaned2 = data2.drop(columns = [\"trace time\", \"convert time\", \"total time\", \"score\", \"fail\"])\n",
    "cleaned2 = cleaned2.rename(columns = {\"fill time\": \"time\"})\n",
    "cleaned2[\"time\"] /= 1e9\n",
    "cleaned2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:46:20.819196Z",
     "iopub.status.busy": "2023-02-27T11:46:20.818521Z",
     "iopub.status.idle": "2023-02-27T11:46:20.820917Z",
     "shell.execute_reply": "2023-02-27T11:46:20.821388Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>algorithm</th>\n",
       "      <th>time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ours (no trace 32-32)</td>\n",
       "      <td>1.033478</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ours (trace 32-32)</td>\n",
       "      <td>1.412761</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ours (trace 32-64)</td>\n",
       "      <td>1.669460</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>editdist</td>\n",
       "      <td>0.476567</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>non-diff</td>\n",
       "      <td>0.681717</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>diff-raw</td>\n",
       "      <td>0.634119</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>libgaba</td>\n",
       "      <td>0.452611</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>edlib</td>\n",
       "      <td>28.046347</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>seqan</td>\n",
       "      <td>90.098655</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               algorithm       time\n",
       "0  ours (no trace 32-32)   1.033478\n",
       "1     ours (trace 32-32)   1.412761\n",
       "2     ours (trace 32-64)   1.669460\n",
       "3               editdist   0.476567\n",
       "4               non-diff   0.681717\n",
       "5               diff-raw   0.634119\n",
       "6                libgaba   0.452611\n",
       "7                  edlib  28.046347\n",
       "8                  seqan  90.098655"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cleaned = data.drop(index = [1, 3, 5])\n",
    "cleaned = cleaned.drop(columns = [\"dataset\"])\n",
    "cleaned = cleaned.append(cleaned2, ignore_index = True)\n",
    "cleaned"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "25kbp Nanopore Reads Benchmark (AVX2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:46:20.841149Z",
     "iopub.status.busy": "2023-02-27T11:46:20.840536Z",
     "iopub.status.idle": "2023-02-27T11:46:21.590379Z",
     "shell.execute_reply": "2023-02-27T11:46:21.590783Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<div id=\"altair-viz-b4590267238d4d34a286fbde9886388c\"></div>\n",
       "<script type=\"text/javascript\">\n",
       "  (function(spec, embedOpt){\n",
       "    let outputDiv = document.currentScript.previousElementSibling;\n",
       "    if (outputDiv.id !== \"altair-viz-b4590267238d4d34a286fbde9886388c\") {\n",
       "      outputDiv = document.getElementById(\"altair-viz-b4590267238d4d34a286fbde9886388c\");\n",
       "    }\n",
       "    const paths = {\n",
       "      \"vega\": \"https://cdn.jsdelivr.net/npm//vega@5?noext\",\n",
       "      \"vega-lib\": \"https://cdn.jsdelivr.net/npm//vega-lib?noext\",\n",
       "      \"vega-lite\": \"https://cdn.jsdelivr.net/npm//vega-lite@4.8.1?noext\",\n",
       "      \"vega-embed\": \"https://cdn.jsdelivr.net/npm//vega-embed@6?noext\",\n",
       "    };\n",
       "\n",
       "    function loadScript(lib) {\n",
       "      return new Promise(function(resolve, reject) {\n",
       "        var s = document.createElement('script');\n",
       "        s.src = paths[lib];\n",
       "        s.async = true;\n",
       "        s.onload = () => resolve(paths[lib]);\n",
       "        s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
       "        document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "      });\n",
       "    }\n",
       "\n",
       "    function showError(err) {\n",
       "      outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
       "      throw err;\n",
       "    }\n",
       "\n",
       "    function displayChart(vegaEmbed) {\n",
       "      vegaEmbed(outputDiv, spec, embedOpt)\n",
       "        .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
       "    }\n",
       "\n",
       "    if(typeof define === \"function\" && define.amd) {\n",
       "      requirejs.config({paths});\n",
       "      require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
       "    } else if (typeof vegaEmbed === \"function\") {\n",
       "      displayChart(vegaEmbed);\n",
       "    } else {\n",
       "      loadScript(\"vega\")\n",
       "        .then(() => loadScript(\"vega-lite\"))\n",
       "        .then(() => loadScript(\"vega-embed\"))\n",
       "        .catch(showError)\n",
       "        .then(() => displayChart(vegaEmbed));\n",
       "    }\n",
       "  })({\"config\": {\"view\": {\"continuousWidth\": 400, \"continuousHeight\": 300}}, \"layer\": [{\"mark\": {\"type\": \"point\", \"filled\": true, \"opacity\": 1}, \"encoding\": {\"x\": {\"type\": \"quantitative\", \"axis\": {\"grid\": true, \"title\": \"time (s)\"}, \"field\": \"time\", \"scale\": {\"type\": \"log\"}}, \"y\": {\"type\": \"nominal\", \"axis\": {\"grid\": true}, \"field\": \"algorithm\", \"sort\": {\"field\": \"time\"}}}, \"transform\": [{\"filter\": \"(((datum.algorithm !== 'ours (trace 32-32)') && (datum.algorithm !== 'ours (no trace 32-32)')) && (datum.algorithm !== 'ours (trace 32-64)'))\"}]}, {\"mark\": {\"type\": \"point\", \"color\": \"red\", \"filled\": true}, \"encoding\": {\"x\": {\"type\": \"quantitative\", \"axis\": {\"grid\": true, \"title\": \"time (s)\"}, \"field\": \"time\", \"scale\": {\"type\": \"log\"}}, \"y\": {\"type\": \"nominal\", \"axis\": {\"grid\": true}, \"field\": \"algorithm\", \"sort\": {\"field\": \"time\"}}}, \"transform\": [{\"filter\": \"(((datum.algorithm === 'ours (trace 32-32)') || (datum.algorithm === 'ours (no trace 32-32)')) || (datum.algorithm === 'ours (trace 32-64)'))\"}]}], \"data\": {\"url\": \"http://localhost:23517/3680e40beaba936e658bfaf5de96254e.json\"}, \"height\": 150, \"width\": 150, \"$schema\": \"https://vega.github.io/schema/vega-lite/v4.8.1.json\"}, {\"mode\": \"vega-lite\"});\n",
       "</script>"
      ],
      "text/plain": [
       "alt.LayerChart(...)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chart1 = alt.Chart(cleaned).mark_point(opacity = 1, filled = True).encode(\n",
    "    x = alt.X(\"time\", axis = alt.Axis(title = \"time (s)\", grid = True), scale = alt.Scale(type = \"log\")),\n",
    "    y = alt.Y(\"algorithm\", axis = alt.Axis(grid = True), sort = alt.EncodingSortField(field = \"time\"))\n",
    ").transform_filter((datum.algorithm != \"ours (trace 32-32)\") & (datum.algorithm != \"ours (no trace 32-32)\") & (datum.algorithm != \"ours (trace 32-64)\"))\n",
    "\n",
    "chart2 = alt.Chart(cleaned).mark_point(color = \"red\", filled = True).encode(\n",
    "    x = alt.X(\"time\", axis = alt.Axis(title = \"time (s)\", grid = True), scale = alt.Scale(type = \"log\")),\n",
    "    y = alt.Y(\"algorithm\", axis = alt.Axis(grid = True), sort = alt.EncodingSortField(field = \"time\"))\n",
    ").transform_filter((datum.algorithm == \"ours (trace 32-32)\") | (datum.algorithm == \"ours (no trace 32-32)\") | (datum.algorithm == \"ours (trace 32-64)\"))\n",
    "\n",
    "c = (chart1 + chart2).properties(\n",
    "    width = 150,\n",
    "    height = 150\n",
    ")\n",
    "save(c, \"nanopore_bench.pdf\")\n",
    "c"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Sequence-to-Profile Alignment Benchmark"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:46:21.593980Z",
     "iopub.status.busy": "2023-02-27T11:46:21.593590Z",
     "iopub.status.idle": "2023-02-27T11:46:33.256268Z",
     "shell.execute_reply": "2023-02-27T11:46:33.256824Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['size, time',\n",
       " '32-32, 0.150358618',\n",
       " '32-64, 0.174074908',\n",
       " '32-128, 0.200178733',\n",
       " '128-128, 0.202823522',\n",
       " 'parasail, 0.579455554',\n",
       " '# Done!']"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "output = !cd .. && cargo run --example pssm_bench --release --features simd_avx2 --quiet\n",
    "output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:46:33.260059Z",
     "iopub.status.busy": "2023-02-27T11:46:33.259583Z",
     "iopub.status.idle": "2023-02-27T11:46:33.266791Z",
     "shell.execute_reply": "2023-02-27T11:46:33.267338Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>size</th>\n",
       "      <th>time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>32-32</td>\n",
       "      <td>0.150359</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>32-64</td>\n",
       "      <td>0.174075</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>32-128</td>\n",
       "      <td>0.200179</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>128-128</td>\n",
       "      <td>0.202824</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>parasail</td>\n",
       "      <td>0.579456</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       size      time\n",
       "0     32-32  0.150359\n",
       "1     32-64  0.174075\n",
       "2    32-128  0.200179\n",
       "3   128-128  0.202824\n",
       "4  parasail  0.579456"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = csv_to_pandas(output)\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:46:33.272519Z",
     "iopub.status.busy": "2023-02-27T11:46:33.271983Z",
     "iopub.status.idle": "2023-02-27T11:46:33.274557Z",
     "shell.execute_reply": "2023-02-27T11:46:33.274054Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  block size  time\n",
      "0      32-32  0.15\n",
      "1      32-64  0.17\n",
      "2     32-128   0.2\n",
      "3    128-128   0.2\n",
      "4   parasail  0.58\n"
     ]
    }
   ],
   "source": [
    "table = data.copy()\n",
    "table = table.rename(columns = {\"size\": \"block size\"})\n",
    "table[\"time\"] = table[\"time\"].map(\"{:.2}\".format)\n",
    "print(table)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "SCOP Sequence-to-Profile Alignment Benchmark (AVX2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:46:33.294570Z",
     "iopub.status.busy": "2023-02-27T11:46:33.294126Z",
     "iopub.status.idle": "2023-02-27T11:46:34.048649Z",
     "shell.execute_reply": "2023-02-27T11:46:34.049062Z"
    },
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<div id=\"altair-viz-3e1cab1386be43e19ce13760e05d3735\"></div>\n",
       "<script type=\"text/javascript\">\n",
       "  (function(spec, embedOpt){\n",
       "    let outputDiv = document.currentScript.previousElementSibling;\n",
       "    if (outputDiv.id !== \"altair-viz-3e1cab1386be43e19ce13760e05d3735\") {\n",
       "      outputDiv = document.getElementById(\"altair-viz-3e1cab1386be43e19ce13760e05d3735\");\n",
       "    }\n",
       "    const paths = {\n",
       "      \"vega\": \"https://cdn.jsdelivr.net/npm//vega@5?noext\",\n",
       "      \"vega-lib\": \"https://cdn.jsdelivr.net/npm//vega-lib?noext\",\n",
       "      \"vega-lite\": \"https://cdn.jsdelivr.net/npm//vega-lite@4.8.1?noext\",\n",
       "      \"vega-embed\": \"https://cdn.jsdelivr.net/npm//vega-embed@6?noext\",\n",
       "    };\n",
       "\n",
       "    function loadScript(lib) {\n",
       "      return new Promise(function(resolve, reject) {\n",
       "        var s = document.createElement('script');\n",
       "        s.src = paths[lib];\n",
       "        s.async = true;\n",
       "        s.onload = () => resolve(paths[lib]);\n",
       "        s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
       "        document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "      });\n",
       "    }\n",
       "\n",
       "    function showError(err) {\n",
       "      outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
       "      throw err;\n",
       "    }\n",
       "\n",
       "    function displayChart(vegaEmbed) {\n",
       "      vegaEmbed(outputDiv, spec, embedOpt)\n",
       "        .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
       "    }\n",
       "\n",
       "    if(typeof define === \"function\" && define.amd) {\n",
       "      requirejs.config({paths});\n",
       "      require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
       "    } else if (typeof vegaEmbed === \"function\") {\n",
       "      displayChart(vegaEmbed);\n",
       "    } else {\n",
       "      loadScript(\"vega\")\n",
       "        .then(() => loadScript(\"vega-lite\"))\n",
       "        .then(() => loadScript(\"vega-embed\"))\n",
       "        .catch(showError)\n",
       "        .then(() => displayChart(vegaEmbed));\n",
       "    }\n",
       "  })({\"config\": {\"view\": {\"continuousWidth\": 400, \"continuousHeight\": 300}}, \"layer\": [{\"mark\": \"bar\", \"encoding\": {\"color\": {\"type\": \"nominal\", \"field\": \"size\", \"legend\": null, \"sort\": [\"32-32\", \"32-64\", \"32-128\", \"128-128\", \"parasail\"]}, \"x\": {\"type\": \"nominal\", \"field\": \"size\", \"sort\": [\"32-32\", \"32-64\", \"32-128\", \"128-128\", \"parasail\"], \"title\": \"block size\"}, \"y\": {\"type\": \"quantitative\", \"axis\": {\"title\": \"time (s)\"}, \"field\": \"time\"}}, \"height\": 100, \"transform\": [{\"filter\": \"(datum.size !== '2048-2048')\"}], \"width\": 75}, {\"mark\": {\"type\": \"text\", \"dy\": -4, \"size\": 8}, \"encoding\": {\"color\": {\"value\": \"black\"}, \"text\": {\"type\": \"quantitative\", \"field\": \"time\", \"format\": \".2f\"}, \"x\": {\"type\": \"nominal\", \"field\": \"size\", \"sort\": [\"32-32\", \"32-64\", \"32-128\", \"128-128\", \"parasail\"], \"title\": \"block size\"}, \"y\": {\"type\": \"quantitative\", \"axis\": {\"title\": \"time (s)\"}, \"field\": \"time\"}}, \"height\": 100, \"transform\": [{\"filter\": \"(datum.size !== '2048-2048')\"}], \"width\": 75}], \"data\": {\"url\": \"http://localhost:23517/aa401262e5e42529f7aca5f78dc0aa2b.json\"}, \"$schema\": \"https://vega.github.io/schema/vega-lite/v4.8.1.json\"}, {\"mode\": \"vega-lite\"});\n",
       "</script>"
      ],
      "text/plain": [
       "alt.LayerChart(...)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = alt.Chart(data).mark_bar().encode(\n",
    "    x = alt.X(\"size\", title = \"block size\", sort = [\"32-32\", \"32-64\", \"32-128\", \"128-128\", \"parasail\"]),\n",
    "    y = alt.Y(\"time\", axis = alt.Axis(title = \"time (s)\")),\n",
    "    color = alt.Color(\"size\", sort = [\"32-32\", \"32-64\", \"32-128\", \"128-128\", \"parasail\"], legend = None)\n",
    ").transform_filter(\n",
    "    datum.size != \"2048-2048\"\n",
    ").properties(\n",
    "    width = 75,\n",
    "    height = 100\n",
    ")\n",
    "t = c.mark_text(dy = -4, size = 8).encode(text = alt.Text(\"time\", format = \".2f\"), color = alt.value(\"black\"))\n",
    "c = c + t\n",
    "save(c, \"pssm_size_bench.pdf\")\n",
    "c"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## WASM SIMD\n",
    "\n",
    "[Wasmtime](https://wasmtime.dev/) is needed to run the webassembly code."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:46:34.052396Z",
     "iopub.status.busy": "2023-02-27T11:46:34.052013Z",
     "iopub.status.idle": "2023-02-27T11:47:07.493267Z",
     "shell.execute_reply": "2023-02-27T11:47:07.493680Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['bench_rustbio_aa_100_1000\\t24,067,946',\n",
       " 'bench_rustbio_aa_10_100\\t254,862',\n",
       " 'bench_scan_aa_1000_10000\\t829,802',\n",
       " 'bench_scan_aa_1000_10000_insert\\t10,785,694',\n",
       " 'bench_scan_aa_1000_10000_small\\t578,308',\n",
       " 'bench_scan_aa_1000_10000_trace\\t1,995,010',\n",
       " 'bench_scan_aa_100_1000\\t74,559',\n",
       " 'bench_scan_aa_100_1000_insert\\t156,641',\n",
       " 'bench_scan_aa_100_1000_small\\t57,182',\n",
       " 'bench_scan_aa_100_1000_trace\\t220,585',\n",
       " 'bench_scan_aa_10_100\\t6,824',\n",
       " 'bench_scan_aa_10_100_insert\\t7,029',\n",
       " 'bench_scan_aa_10_100_small\\t5,345',\n",
       " 'bench_scan_aa_10_100_trace\\t84,180',\n",
       " 'bench_scan_nuc_1000_10000\\t556,340',\n",
       " 'bench_scan_nuc_100_1000\\t54,636']"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "output = !CARGO_TARGET_WASM32_WASI_RUNNER=\"wasmtime --wasm-features simd --\" cargo bench --target=wasm32-wasi --features simd_wasm --quiet -- --nocapture | grep 'bench:' | awk '{print $2\"\\t\"$5}'\n",
    "output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:47:07.499150Z",
     "iopub.status.busy": "2023-02-27T11:47:07.498303Z",
     "iopub.status.idle": "2023-02-27T11:47:07.501332Z",
     "shell.execute_reply": "2023-02-27T11:47:07.501755Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['algorithm\\talphabet\\tk\\tlength\\tproperty\\ttime',\n",
       " 'rust bio\\tprotein\\t100\\t1000\\tdefault\\t24,067,946',\n",
       " 'rust bio\\tprotein\\t10\\t100\\tdefault\\t254,862',\n",
       " 'ours\\tprotein\\t1000\\t10000\\tdefault\\t829,802',\n",
       " 'ours\\tprotein\\t1000\\t10000\\tinsert\\t10,785,694',\n",
       " 'ours\\tprotein\\t1000\\t10000\\tsmall\\t578,308',\n",
       " 'ours\\tprotein\\t1000\\t10000\\ttrace\\t1,995,010',\n",
       " 'ours\\tprotein\\t100\\t1000\\tdefault\\t74,559',\n",
       " 'ours\\tprotein\\t100\\t1000\\tinsert\\t156,641',\n",
       " 'ours\\tprotein\\t100\\t1000\\tsmall\\t57,182',\n",
       " 'ours\\tprotein\\t100\\t1000\\ttrace\\t220,585',\n",
       " 'ours\\tprotein\\t10\\t100\\tdefault\\t6,824',\n",
       " 'ours\\tprotein\\t10\\t100\\tinsert\\t7,029',\n",
       " 'ours\\tprotein\\t10\\t100\\tsmall\\t5,345',\n",
       " 'ours\\tprotein\\t10\\t100\\ttrace\\t84,180',\n",
       " 'ours\\tnucleotide\\t1000\\t10000\\tdefault\\t556,340',\n",
       " 'ours\\tnucleotide\\t100\\t1000\\tdefault\\t54,636']"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cleaned = [\"algorithm\\talphabet\\tk\\tlength\\tproperty\\ttime\"]\n",
    "names = [\"rustbio_aa\", \"scan_aa\", \"scan_nuc\"]\n",
    "new_names = [\"rust bio\\tprotein\", \"ours\\tprotein\", \"ours\\tnucleotide\"]\n",
    "\n",
    "for o in output:\n",
    "    o = o[len(\"bench_\"):]\n",
    "    for n, nn in zip(names, new_names):\n",
    "        if o.startswith(n):\n",
    "            suffix = o[len(n):].replace(\"_\", \"\\t\")\n",
    "            o = nn + suffix\n",
    "            break\n",
    "    if len(o.split(\"\\t\")) < len(cleaned[0].split(\"\\t\")):\n",
    "        insert_idx = o.rindex(\"\\t\")\n",
    "        o = o[:insert_idx] + \"\\tdefault\" + o[insert_idx:]\n",
    "    cleaned.append(o)\n",
    "\n",
    "cleaned"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:47:07.504482Z",
     "iopub.status.busy": "2023-02-27T11:47:07.504081Z",
     "iopub.status.idle": "2023-02-27T11:47:07.513915Z",
     "shell.execute_reply": "2023-02-27T11:47:07.514320Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>algorithm</th>\n",
       "      <th>alphabet</th>\n",
       "      <th>k</th>\n",
       "      <th>length</th>\n",
       "      <th>property</th>\n",
       "      <th>time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>rust bio</td>\n",
       "      <td>protein</td>\n",
       "      <td>100</td>\n",
       "      <td>1000</td>\n",
       "      <td>default</td>\n",
       "      <td>24067946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>rust bio</td>\n",
       "      <td>protein</td>\n",
       "      <td>10</td>\n",
       "      <td>100</td>\n",
       "      <td>default</td>\n",
       "      <td>254862</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>1000</td>\n",
       "      <td>10000</td>\n",
       "      <td>default</td>\n",
       "      <td>829802</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>1000</td>\n",
       "      <td>10000</td>\n",
       "      <td>insert</td>\n",
       "      <td>10785694</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>1000</td>\n",
       "      <td>10000</td>\n",
       "      <td>small</td>\n",
       "      <td>578308</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>1000</td>\n",
       "      <td>10000</td>\n",
       "      <td>trace</td>\n",
       "      <td>1995010</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>100</td>\n",
       "      <td>1000</td>\n",
       "      <td>default</td>\n",
       "      <td>74559</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>100</td>\n",
       "      <td>1000</td>\n",
       "      <td>insert</td>\n",
       "      <td>156641</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>100</td>\n",
       "      <td>1000</td>\n",
       "      <td>small</td>\n",
       "      <td>57182</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>100</td>\n",
       "      <td>1000</td>\n",
       "      <td>trace</td>\n",
       "      <td>220585</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>10</td>\n",
       "      <td>100</td>\n",
       "      <td>default</td>\n",
       "      <td>6824</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>10</td>\n",
       "      <td>100</td>\n",
       "      <td>insert</td>\n",
       "      <td>7029</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>10</td>\n",
       "      <td>100</td>\n",
       "      <td>small</td>\n",
       "      <td>5345</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>ours</td>\n",
       "      <td>protein</td>\n",
       "      <td>10</td>\n",
       "      <td>100</td>\n",
       "      <td>trace</td>\n",
       "      <td>84180</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>ours</td>\n",
       "      <td>nucleotide</td>\n",
       "      <td>1000</td>\n",
       "      <td>10000</td>\n",
       "      <td>default</td>\n",
       "      <td>556340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>ours</td>\n",
       "      <td>nucleotide</td>\n",
       "      <td>100</td>\n",
       "      <td>1000</td>\n",
       "      <td>default</td>\n",
       "      <td>54636</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   algorithm    alphabet     k  length property      time\n",
       "0   rust bio     protein   100    1000  default  24067946\n",
       "1   rust bio     protein    10     100  default    254862\n",
       "2       ours     protein  1000   10000  default    829802\n",
       "3       ours     protein  1000   10000   insert  10785694\n",
       "4       ours     protein  1000   10000    small    578308\n",
       "5       ours     protein  1000   10000    trace   1995010\n",
       "6       ours     protein   100    1000  default     74559\n",
       "7       ours     protein   100    1000   insert    156641\n",
       "8       ours     protein   100    1000    small     57182\n",
       "9       ours     protein   100    1000    trace    220585\n",
       "10      ours     protein    10     100  default      6824\n",
       "11      ours     protein    10     100   insert      7029\n",
       "12      ours     protein    10     100    small      5345\n",
       "13      ours     protein    10     100    trace     84180\n",
       "14      ours  nucleotide  1000   10000  default    556340\n",
       "15      ours  nucleotide   100    1000  default     54636"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = csv_to_pandas(cleaned, d = \"\\t\", t = \",\")\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:47:07.518392Z",
     "iopub.status.busy": "2023-02-27T11:47:07.517903Z",
     "iopub.status.idle": "2023-02-27T11:47:07.519916Z",
     "shell.execute_reply": "2023-02-27T11:47:07.520318Z"
    }
   },
   "outputs": [],
   "source": [
    "data[\"algorithm property\"] = data[\"algorithm\"] + \" \" + data[\"property\"]\n",
    "data[\"time\"] /= 1000"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Random Protein Sequences Benchmark (WASM SIMD)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-27T11:47:07.538555Z",
     "iopub.status.busy": "2023-02-27T11:47:07.538143Z",
     "iopub.status.idle": "2023-02-27T11:47:08.292006Z",
     "shell.execute_reply": "2023-02-27T11:47:08.292504Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<div id=\"altair-viz-3a5318da60844c848901576928e9bac6\"></div>\n",
       "<script type=\"text/javascript\">\n",
       "  (function(spec, embedOpt){\n",
       "    let outputDiv = document.currentScript.previousElementSibling;\n",
       "    if (outputDiv.id !== \"altair-viz-3a5318da60844c848901576928e9bac6\") {\n",
       "      outputDiv = document.getElementById(\"altair-viz-3a5318da60844c848901576928e9bac6\");\n",
       "    }\n",
       "    const paths = {\n",
       "      \"vega\": \"https://cdn.jsdelivr.net/npm//vega@5?noext\",\n",
       "      \"vega-lib\": \"https://cdn.jsdelivr.net/npm//vega-lib?noext\",\n",
       "      \"vega-lite\": \"https://cdn.jsdelivr.net/npm//vega-lite@4.8.1?noext\",\n",
       "      \"vega-embed\": \"https://cdn.jsdelivr.net/npm//vega-embed@6?noext\",\n",
       "    };\n",
       "\n",
       "    function loadScript(lib) {\n",
       "      return new Promise(function(resolve, reject) {\n",
       "        var s = document.createElement('script');\n",
       "        s.src = paths[lib];\n",
       "        s.async = true;\n",
       "        s.onload = () => resolve(paths[lib]);\n",
       "        s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
       "        document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
       "      });\n",
       "    }\n",
       "\n",
       "    function showError(err) {\n",
       "      outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
       "      throw err;\n",
       "    }\n",
       "\n",
       "    function displayChart(vegaEmbed) {\n",
       "      vegaEmbed(outputDiv, spec, embedOpt)\n",
       "        .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
       "    }\n",
       "\n",
       "    if(typeof define === \"function\" && define.amd) {\n",
       "      requirejs.config({paths});\n",
       "      require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
       "    } else if (typeof vegaEmbed === \"function\") {\n",
       "      displayChart(vegaEmbed);\n",
       "    } else {\n",
       "      loadScript(\"vega\")\n",
       "        .then(() => loadScript(\"vega-lite\"))\n",
       "        .then(() => loadScript(\"vega-embed\"))\n",
       "        .catch(showError)\n",
       "        .then(() => displayChart(vegaEmbed));\n",
       "    }\n",
       "  })({\"config\": {\"view\": {\"continuousWidth\": 400, \"continuousHeight\": 300}}, \"data\": {\"url\": \"http://localhost:23517/c4277cacd183f444e88ea767a2e04746.json\"}, \"mark\": {\"type\": \"point\", \"filled\": true, \"opacity\": 1}, \"encoding\": {\"color\": {\"type\": \"nominal\", \"field\": \"length\"}, \"shape\": {\"type\": \"nominal\", \"field\": \"length\"}, \"x\": {\"type\": \"quantitative\", \"axis\": {\"title\": \"time (us)\"}, \"field\": \"time\", \"scale\": {\"type\": \"log\"}}, \"y\": {\"type\": \"nominal\", \"axis\": {\"grid\": true, \"title\": \"algorithm\"}, \"field\": \"algorithm property\", \"sort\": {\"field\": \"time\"}}}, \"height\": 150, \"transform\": [{\"filter\": \"(datum.alphabet === 'protein')\"}], \"width\": 200, \"$schema\": \"https://vega.github.io/schema/vega-lite/v4.8.1.json\"}, {\"mode\": \"vega-lite\"});\n",
       "</script>"
      ],
      "text/plain": [
       "alt.Chart(...)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = alt.Chart(data).mark_point(opacity = 1, filled = True).encode(\n",
    "    x = alt.X(\"time\", axis = alt.Axis(title = \"time (us)\"), scale = alt.Scale(type = \"log\")),\n",
    "    y = alt.Y(\"algorithm property\", axis = alt.Axis(title = \"algorithm\", grid = True), sort = alt.EncodingSortField(field = \"time\")),\n",
    "    color = \"length:N\",\n",
    "    shape = \"length:N\"\n",
    ").transform_filter(\n",
    "    datum.alphabet == \"protein\"\n",
    ").properties(\n",
    "    width = 200,\n",
    "    height = 150\n",
    ")\n",
    "save(c, \"random_protein_bench_wasm.pdf\")\n",
    "c"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
